<template>

    <van-cell :to="`/Aticle/${article.art_id}`" class="article-item">
        <template #title>
            <div class="title van-multi-ellipsis--l2">{{ article.title }}</div>
        </template>
        <template #label>
            <!-- 判断三个图片 -->
            <div v-if="article.cover.type === 3" class="cover-wrap">
                <div v-for="(img, index) in article.cover.images" :key="index" class="cover-item">
                    <van-image class="cover-item-img" fit="cover" width="100" height="100" :src="img" />
                </div>
            </div>
            <div class="label-info-wrap">
                <span>{{ article.aut_name }}</span>
                <span>{{ article.comm_count }}</span>
                <span>{{ dayJS().to(dayJS(article.pubdate)) }}</span>
            </div>
        </template>
        <!-- 判断单个图片 -->
        <template #default v-if="article.cover.type === 1">
            <van-image class="right-cover" fit="cover" width="100" height="100" :src="article.cover.images[0]" />
        </template>
    </van-cell>
</template>

<script>
import { inject } from 'vue'
export default {
  name: 'article-item',
  props: {
    article: {
      type: Object,
      required: true
    }
  },
  setup () {
    // vue3中在<script setup>中获取全局内容 Provide / Inject
    const dayJS = inject('dayJS')
    return {
      dayJS
    }
  }

}
</script>

<style scoped lang="less">
.article-item {
    .title {
        font-size: 32px;
        color: #3a3a3a;
    }

    .right-cover {
        width: 100%;
        height: 146px;
    }

    .label-info-wrap {
        padding-top: 50px;
    }

    .label-info-wrap span {
        font-size: 22px;
        color: #b4b4b4;
        margin-right: 25px;
    }

    .cover-wrap {
        display: flex;
        //padding: 30px 0;

        .cover-item {
            flex: 1;
            height: 146px;

            &:not(:last-child) {
                padding-right: 4px;
            }

            .cover-item-img {
                width: 100%;
                height: 146px;
            }
        }
    }
}
</style>
